<!--
 * @Author: your name
 * @Date: 2021-03-31 20:39:00
 * @LastEditTime: 2021-04-16 09:36:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \web\node\views\back\sowing_list.html
-->
<!-- 继承base基础模板 -->
{%  extends "back/base.html" %}

<!-- 留槽 样式 -->
{% block style %}
{% endblock %}

 <!-- 留槽 主要内容 -->
{% block body %}
    <div class="container-fluid">
    <div class="body advert">
        <ol class="breadcrumb">
            <li><a href="/back/s_list">轮播图管理</a></li>
            <li class="active">轮播图列表</li>
        </ol>
        <div class="page-title">
            <a href="/back/s_add" class="btn btn-danger btn-sm pull-right">添加轮播图</a>
        </div>
        <div class="panel panel-default">
            {% if sowings.length > 0 %}
                <table class="table table-bordered">
                <thead>
                    <tr>
                        <td>序号</td>
                        <th>轮播图名称</th>
                        <th>轮播缩略图</th>
                        <th>跳转链接</th>
                        <th>上架时间</th>
                        <th>下架时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody> 
                    {% for sowing in sowings %}
                        <tr>
                            <td>{{loop.index}}</td>
                            <td>{{sowing.image_title}}</td>
                            <td> 
                                <img src="/uploads/{{sowing.image_url}}" alt="" style="width: 300px;">
                            </td>
                            <td>{{sowing.image_link}}</td>
                            <td>{{sowing.s_time}}</td>
                            <td>{{sowing.e_time}}</td>
                            <td>
                                <a data-id="{{sowing._id}}" class="btn btn-primary btn-xs btn-edit">编辑</a>
                                <a data-id="{{sowing._id}}" class="btn btn-danger btn-xs btn-del">删除</a>
                            </td>
                        </tr>
                    {% endfor %}
                   
                </tbody>
                </table>
            {% else %}
                <div style="text-align: center; padding: 30px 0;">
                    <a href="/back/s_add" style="cursor: pointer;">页面还没有轮播图,赶紧去添加哟~</a>
                </div>            
            {% endif %}
        </div>
    </div>
    </div>
{% endblock %}

   <!-- 留槽 脚本 -->
{% block script %}
<script>
    $(function(){
        $(".btn-edit").on("click",function(){
            window.location.href = "/back/s_edit?sid=" + $(this).attr("data-id")
        })

        //删除
        $(".btn-del").on("click",function(){
            //发起请求
            $.ajax({
              url: "http://localhost:3000/back/sowing/api/delete/" + $(this).attr("data-id"),
              type: "get",
              success: function (data) {
                  if(data.status === 200){ // 添加成功
                      alert('轮播图删除成功!');
                  }else {
                      alert('轮播图删除失败!');
                  }
                  window.location.reload()
              }
          });

        })
    })
</script>
{% endblock %}


